import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  // 一级路由布局容器
  {
    path: '/',
    // 无论跳转与否，Layout一级组件都会在页面上。
    component: () => import('@/views/Layout'),
    children: [
      {
        path: '/',
        // 初次进入到页面，展示这个Home二级组件
        component: () => import('@/views/Home')
      },
      {
        path: '/category/:id',
        component: () => import('@/views/Category')
      },
      {
        path: '/category/sub/:id',
        component: () => import('@/views/Category/Sub')
      },
      {
        path: '/product/:id',
        component: () => import('@/views/Goods')
      }
    ]
  }
]

// v3通过createRouter()创建router实例。先引入，再创建。
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
